@isTest
private class AssignmentsImportControllerTest {

	static testMethod void testMethod1() {
			 Account acc = TestUtils.createAccount();
        acc.Level__c = '一级医院';
        insert acc;
        
        Product__c p1 = TestUtils.createProduct();
        p1.ProductName__c = '尿有形成份检测稀释液UPS';
        p1.Category0__c = '仪器';

        p1.PriceCompany__c = 'MKSY';
        p1.NCCode__c = '000001';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert p1;

        List<Map<String,String>> dataJson = new List<Map<String,String>>();
        Map<String,String> data = new Map<String,String>();

        data.put('nccode', p1.NCCode__c);
        data.put('sf_ter_account_id',acc.Id );
        data.put('sf_pay_account_id',acc.Id );

        data.put('regent_brand', '迈克生物');
        data.put('regent_cate1','试剂');
        data.put('regent_cate2','生化');

        data.put('owner_area','迈克实业' );
        data.put('owner_year_month','201801');
        data.put('sign_company','迈克生物');
        data.put('coop_start_date','2018-01-01');
        data.put('coop_end_date','2019-12-31');

        data.put('assign_2018','12.0');
        data.put('coop_year','2');
        data.put('is_all_brand','是');

       // data.put('is_all_maccura_brand','是');
       // data.put('sf_mc_no',[select Name from Measure_Calculate__c].Name );
        data.put('invname', '尿有形成份检测稀释液UPS');
        data.put('mcode','x00001');
        data.put('invtype', 'tt');
        data.put('task_resource', '合同规定');
        //data.put('is_trid_from_contract', '否');
        data.put('detail_note', '否');
        data.put('equip_note', '否');


        dataJson.add(data);

        AssignmentsImportController aic = new AssignmentsImportController();

         PageReference page2 = new PageReference('/apex/AssingmentImportNew');
         System.Test.setCurrentPage(page2);

         aic.init();
         aic.getDetails();
         Map<String,List<String>> objMap =new Map<String,List<String>>();
         objMap.put('Account', new List<String>{'sf_ter_account_id','sf_pay_account_id'});
          objMap.put('Product__c', new List<String>{'NCCode__c'});

		Map<String,List<String>> vMap =new Map<String,List<String>>();
         objMap.put('Account', new List<String>{acc.Id});
         objMap.put('Product__c', new List<String>{p1.NCCode__c});

         AssignmentsImportController.validateRefValue( objMap,  vMap);

         aic.saveJson = EncodingUtil.urlEncode(JSON.serialize(dataJson), 'UTF-8');
         aic.save();

         System.debug('AssignmentsImportControllerTest==>'+ aic.msg);

        TaskTrackingImport__c tt =  [select Id,RecordType.DeveloperName  from TaskTrackingImport__c  where RecordType.DeveloperName = 'ApprovalForm'];
         System.debug('AssignmentsImportControllerTest==>'+ tt.RecordType.DeveloperName );


          TaskTrackingImport__c tt1 =  [select Id,RecordType.DeveloperName ,(select Classification1__c, Classification2__c,ReagentBrand__c,GroupGrossProfit__c,SubCompanyGrossProfit__c,
             Years__c,WhetherNew__c,WhetherCovered__c,ReagentAssignments__c
             from TaskTrackingImport__r )   from TaskTrackingImport__c where MainApply__c =:tt.Id ];
                 System.debug('AssignmentsImportControllerTest==>'+ tt1 );



         PageReference page = new PageReference('/apex/AssingmentImportNew?id='+tt.Id );
         System.Test.setCurrentPage(page);
         AssignmentsImportController aic1 = new AssignmentsImportController();

         aic1.init();

         aic1.getDetails();

         System.debug('AssignmentsImportControllerTest==>'+ aic1.dataJson );

         tt.Status__c = '已批准';

         update tt;

         AssignmentsImportController.splitTaskFromImp(tt1.id);


         
         	aic1.saveJson = EncodingUtil.urlEncode(JSON.serialize(new List<String>{'111111'}), 'UTF-8');
            aic1.deleteImport(); 
                     System.debug('AssignmentsImportControllerTest==>'+ aic.msg);

         
         
         

	}
    
}